Replace gdk_threads_add_idle* with g_idle_add()
authorEmmanuele Bassi <ebassi@gnome.org>
Fri, 2 Feb 2018 14:08:02 +0000 (15:08 +0100)
committerEmmanuele Bassi <ebassi@gnome.org>
Sat, 3 Feb 2018 11:06:58 +0000 (12:06 +0100)
The main GDK thread lock is not portable and deprecated.

The only reason why gdk_threads_add_idle() and
gdk_threads_add_idle_full() exist is to allow invoking a callback with
the GDK lock held, in case 3rd party libraries still use the deprecated
gdk_threads_enter()/gdk_threads_leave() API.

Since we're removing the GDK lock, and we're releasing a new major API,
such code cannot exist any more; this means we can use the GLib API for
installing idle callbacks.

https://bugzilla.gnome.org/show_bug.cgi?id=793124

18 files changed:
gdk/broadway/gdkwindow-broadway.c
gdk/quartz/gdkscreen-quartz.c
gdk/x11/gdkasync.c
gtk/a11y/gtkiconviewaccessible.c
gtk/gtkfilechooserwidget.c
gtk/gtkicontheme.c
gtk/gtkmenusectionbox.c
gtk/gtkprintoperation.c
gtk/gtkprintunixdialog.c
gtk/gtksearchenginemodel.c
gtk/gtksearchenginesimple.c
gtk/gtktextview.c
gtk/gtktoolbar.c
gtk/gtktreeview.c
gtk/gtkwidget.c
gtk/gtkwindow.c
tests/stresstest-toolbar.c
testsuite/a11y/tree-relationships.c

index 12fb5256e33aadadd7e442ca58752a80f9bd124b..ebbd03e658be04427b4971a64ce8261aed7d5fc6 100644 (file)
@@ -115,7 +115,7 @@ queue_flush (GdkWindow *window)
 {
   if (flush_id == 0)
     {
-      flush_id = gdk_threads_add_idle (flush_idle, NULL);
+      flush_id = g_idle_add (flush_idle, NULL);
       g_source_set_name_by_id (flush_id, "[gtk+] flush_idle");
     }
 }
index e1f12995cdfbd66d17fea870513f39cb54a3588d..6f53f36a2b83ed05ba4621b74aa506ac461657c0 100644 (file)
@@ -262,7 +262,7 @@ display_reconfiguration_callback (CGDirectDisplayID            display,
        */
       if (!screen->screen_changed_id)
         {
-          screen->screen_changed_id = gdk_threads_add_idle (screen_changed_idle, screen);
+          screen->screen_changed_id = g_idle_add (screen_changed_idle, screen);
           g_source_set_name_by_id (screen->screen_changed_id, "[gtk+] screen_changed_idle");
         }
     }
index d9b84c4af2bdc4ac956d8eb5532f363a78273b4e..31d5b4e48099ed40b4996e273400fde01d5ae7ff 100644 (file)
@@ -173,7 +173,7 @@ send_event_handler (Display *dpy,
       if (state->callback)
         {
           guint id;
-          id = gdk_threads_add_idle (callback_idle, state);
+          id = g_idle_add (callback_idle, state);
           g_source_set_name_by_id (id, "[gtk+] callback_idle");
         }
 
@@ -709,7 +709,7 @@ roundtrip_handler (Display *dpy,
       if (state->callback)
         {
           guint id;
-          id = gdk_threads_add_idle (roundtrip_callback_idle, state);
+          id = g_idle_add (roundtrip_callback_idle, state);
           g_source_set_name_by_id (id, "[gtk+] roundtrip_callback_idle");
         }
 
index eb85522d872805c63acc710d2e85ff5a72ebd4b2..645515a6caa286a789eef503ebd9f413b59c69b5 100644 (file)
@@ -113,7 +113,7 @@ gtk_icon_view_item_accessible_do_action (AtkAction *action,
 
   if (!item->action_idle_handler)
     {
-      item->action_idle_handler = gdk_threads_add_idle (idle_do_action, item);
+      item->action_idle_handler = g_idle_add (idle_do_action, item);
       g_source_set_name_by_id (item->action_idle_handler, "[gtk+] idle_do_action");
     }
 
index 8623fcccaf6332c3ad77e3ed9afb38f104e134a9..47cec72be286d8f571cc3075c81baed7bd7faa1f 100644 (file)
@@ -7447,10 +7447,10 @@ recent_start_loading (GtkFileChooserWidget *impl)
   load_data->items = NULL;
 
   /* begin lazy loading the recent files into the model */
-  priv->load_recent_id = gdk_threads_add_idle_full (G_PRIORITY_DEFAULT,
-                                                    recent_idle_load,
-                                                    load_data,
-                                                    recent_idle_cleanup);
+  priv->load_recent_id = g_idle_add_full (G_PRIORITY_DEFAULT,
+                                          recent_idle_load,
+                                          load_data,
+                                          recent_idle_cleanup);
   g_source_set_name_by_id (priv->load_recent_id, "[gtk+] recent_idle_load");
 }
 
index af2541d555bbfa61621c2bb744babd83d324e90a..afaed8f8023eae6027ae5e02e5fcd79ac04a896a 100644 (file)
@@ -734,9 +734,10 @@ queue_theme_changed (GtkIconTheme *icon_theme)
 
   if (!priv->theme_changed_idle)
     {
-      priv->theme_changed_idle =
-        gdk_threads_add_idle_full (GTK_PRIORITY_RESIZE - 2,
-                                   theme_changed_idle, icon_theme, NULL);
+      priv->theme_changed_idle = g_idle_add_full (GTK_PRIORITY_RESIZE - 2,
+                                                  theme_changed_idle,
+                                                  icon_theme,
+                                                  NULL);
       g_source_set_name_by_id (priv->theme_changed_idle, "[gtk+] theme_changed_idle");
     }
 }
index 31792901428b2921ac6ab513366c8befb315173f..2e56e0157c2b1dc53b4fca390f7914a05aab0554 100644 (file)
@@ -160,9 +160,12 @@ gtk_menu_section_box_schedule_separator_sync (GtkMenuSectionBox *box)
   box = box->toplevel;
 
   if (!box->separator_sync_idle)
-    box->separator_sync_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE, /* before resize... */
-                                                          gtk_menu_section_box_handle_sync_separators,
-                                                          box, NULL);
+    {
+      box->separator_sync_idle = g_idle_add_full (G_PRIORITY_HIGH_IDLE, /* before resize... */
+                                                  gtk_menu_section_box_handle_sync_separators,
+                                                  box, NULL);
+      g_source_set_name_by_id (box->separator_sync_idle, "[gtk+] menu section box handle sync separators");
+    }
 }
 
 static void
index 516f694b0c018595a767caaa0d003ee0d277fd8e..cd2a082af3c63f6967c9a1b45fecc945c166b21d 100644 (file)
@@ -639,10 +639,10 @@ preview_ready (GtkPrintOperationPreview *preview,
 
   g_object_ref (preview);
       
-  id = gdk_threads_add_idle_full (G_PRIORITY_DEFAULT_IDLE + 10,
-                                 preview_print_idle,
-                                 pop,
-                                 preview_print_idle_done);
+  id = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE + 10,
+                        preview_print_idle,
+                        pop,
+                        preview_print_idle_done);
   g_source_set_name_by_id (id, "[gtk+] preview_print_idle");
 }
 
@@ -3076,10 +3076,10 @@ print_pages (GtkPrintOperation       *op,
       priv->manual_number_up_layout = gtk_print_settings_get_number_up_layout (priv->print_settings);
     }
   
-  priv->print_pages_idle_id = gdk_threads_add_idle_full (G_PRIORITY_DEFAULT_IDLE + 10,
-                                                        print_pages_idle, 
-                                                        data, 
-                                                        print_pages_idle_done);
+  priv->print_pages_idle_id = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE + 10,
+                                               print_pages_idle,
+                                               data,
+                                               print_pages_idle_done);
   g_source_set_name_by_id (priv->print_pages_idle_id, "[gtk+] print_pages_idle");
   
   /* Recursive main loop to make sure we don't exit  on sync operations  */
index dea6fd2442aca30bc458e2aee27f5001270c2ba9..6feb0aa58a3171538f64d6db6abee84f8b54d668 100644 (file)
@@ -1935,8 +1935,7 @@ schedule_idle_mark_conflicts (GtkPrintUnixDialog *dialog)
   if (priv->mark_conflicts_id != 0)
     return;
 
-  priv->mark_conflicts_id = gdk_threads_add_idle (mark_conflicts_callback,
-                                        dialog);
+  priv->mark_conflicts_id = g_idle_add (mark_conflicts_callback, dialog);
   g_source_set_name_by_id (priv->mark_conflicts_id, "[gtk+] mark_conflicts_callback");
 }
 
index 6dd735db035c750425a9306f6d42e51247a9565e..2ff615246d69ef7e0eb272576a85de83fc3b5062 100644 (file)
@@ -128,7 +128,7 @@ gtk_search_engine_model_start (GtkSearchEngine *engine)
   if (model->query == NULL)
     return;
 
-  model->idle = gdk_threads_add_idle (do_search, engine);
+  model->idle = g_idle_add (do_search, engine);
   g_source_set_name_by_id (model->idle, "[gtk+] gtk_search_engine_model_start");
 }
 
index 6daf2f863106c80133891799a8af48fe71a97a2d..8f5d4316742deac80932343dc4804dfbb22f8f21 100644 (file)
@@ -180,7 +180,7 @@ send_batch (SearchThreadData *data)
       batch->hits = data->hits;
       batch->thread_data = data;
 
-      id = gdk_threads_add_idle (search_thread_add_hits_idle, batch);
+      id = g_idle_add (search_thread_add_hits_idle, batch);
       g_source_set_name_by_id (id, "[gtk+] search_thread_add_hits_idle");
     }
 
@@ -287,7 +287,7 @@ search_thread_func (gpointer user_data)
   if (!g_cancellable_is_cancelled (data->cancellable))
     send_batch (data);
 
-  id = gdk_threads_add_idle (search_thread_done_idle, data);
+  id = g_idle_add (search_thread_done_idle, data);
   g_source_set_name_by_id (id, "[gtk+] search_thread_done_idle");
 
   return NULL;
index 9679c6568635fbca4ba325fbccd15366a0295cbc..9dbfa525377877cd0f7eef1bf391e41a5aa095a7 100644 (file)
@@ -2659,10 +2659,10 @@ queue_update_im_spot_location (GtkTextView *text_view)
    * so we don't wait until the entire buffer has been validated. */
   if (!priv->im_spot_idle)
     {
-      priv->im_spot_idle = gdk_threads_add_idle_full (GTK_TEXT_VIEW_PRIORITY_VALIDATE - 1,
-                                                     do_update_im_spot_location,
-                                                     text_view,
-                                                     NULL);
+      priv->im_spot_idle = g_idle_add_full (GTK_TEXT_VIEW_PRIORITY_VALIDATE - 1,
+                                            do_update_im_spot_location,
+                                            text_view,
+                                            NULL);
       g_source_set_name_by_id (priv->im_spot_idle, "[gtk+] do_update_im_spot_location");
     }
 }
@@ -4397,7 +4397,7 @@ gtk_text_view_invalidate (GtkTextView *text_view)
   
   if (!priv->first_validate_idle)
     {
-      priv->first_validate_idle = gdk_threads_add_idle_full (GTK_PRIORITY_RESIZE - 2, first_validate_callback, text_view, NULL);
+      priv->first_validate_idle = g_idle_add_full (GTK_PRIORITY_RESIZE - 2, first_validate_callback, text_view, NULL);
       g_source_set_name_by_id (priv->first_validate_idle, "[gtk+] first_validate_callback");
       DV (g_print (G_STRLOC": adding first validate idle %d\n",
                    priv->first_validate_idle));
@@ -4405,7 +4405,7 @@ gtk_text_view_invalidate (GtkTextView *text_view)
       
   if (!priv->incremental_validate_idle)
     {
-      priv->incremental_validate_idle = gdk_threads_add_idle_full (GTK_TEXT_VIEW_PRIORITY_VALIDATE, incremental_validate_callback, text_view, NULL);
+      priv->incremental_validate_idle = g_idle_add_full (GTK_TEXT_VIEW_PRIORITY_VALIDATE, incremental_validate_callback, text_view, NULL);
       g_source_set_name_by_id (priv->incremental_validate_idle, "[gtk+] incremental_validate_callback");
       DV (g_print (G_STRLOC": adding incremental validate idle %d\n",
                    priv->incremental_validate_idle));
index a513abbfdf10ab51745cd08e7475de1e5963b9b1..262ab9f76060adaeb0256dd9d8984147cd96b6f8 100644 (file)
@@ -1002,7 +1002,7 @@ gtk_toolbar_begin_sliding (GtkToolbar *toolbar)
   
   if (!priv->idle_id)
     {
-      priv->idle_id = gdk_threads_add_idle (slide_idle_handler, toolbar);
+      priv->idle_id = g_idle_add (slide_idle_handler, toolbar);
       g_source_set_name_by_id (priv->idle_id, "[gtk+] slide_idle_handler");
     }
 
index d829f0c9c7d7c1297e707435d4ba3d939d2cdcb4..85711511e7b88b05a6cf8c23d02f40cc39864c35 100644 (file)
@@ -6726,7 +6726,7 @@ install_presize_handler (GtkTreeView *tree_view)
   if (! tree_view->priv->validate_rows_timer)
     {
       tree_view->priv->validate_rows_timer =
-       gdk_threads_add_idle_full (GTK_TREE_VIEW_PRIORITY_VALIDATE, (GSourceFunc) validate_rows, tree_view, NULL);
+       g_idle_add_full (GTK_TREE_VIEW_PRIORITY_VALIDATE, (GSourceFunc) validate_rows, tree_view, NULL);
       g_source_set_name_by_id (tree_view->priv->validate_rows_timer, "[gtk+] validate_rows");
     }
 }
@@ -6755,7 +6755,7 @@ install_scroll_sync_handler (GtkTreeView *tree_view)
   if (!tree_view->priv->scroll_sync_timer)
     {
       tree_view->priv->scroll_sync_timer =
-       gdk_threads_add_idle_full (GTK_TREE_VIEW_PRIORITY_SCROLL_SYNC, (GSourceFunc) scroll_sync_handler, tree_view, NULL);
+       g_idle_add_full (GTK_TREE_VIEW_PRIORITY_SCROLL_SYNC, (GSourceFunc) scroll_sync_handler, tree_view, NULL);
       g_source_set_name_by_id (tree_view->priv->scroll_sync_timer, "[gtk+] scroll_sync_handler");
     }
 }
index b1386298bf728694460357190dd84ad048c541cf..d67c7a9e2f97f61c5f246818251766b5f6b6ba61 100644 (file)
@@ -11813,7 +11813,7 @@ gtk_widget_queue_tooltip_query (GtkWidget *widget)
 
   if (tooltip_query_id == 0)
     {
-      tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
+      tooltip_query_id = g_idle_add (tooltip_query_idle, NULL);
       g_source_set_name_by_id (tooltip_query_id, "[gtk+] tooltip_query_idle");
     }
 }
index 147e5050582e482eae3e71c5a47ffcd58c815f94..296aa5dc1ffdbeaebb7593fc12ac38d3abc0a142 100644 (file)
@@ -2930,7 +2930,7 @@ _gtk_window_notify_keys_changed (GtkWindow *window)
 
   if (!priv->keys_changed_handler)
     {
-      priv->keys_changed_handler = gdk_threads_add_idle (handle_keys_changed, window);
+      priv->keys_changed_handler = g_idle_add (handle_keys_changed, window);
       g_source_set_name_by_id (priv->keys_changed_handler, "[gtk+] handle_keys_changed");
     }
 }
@@ -11027,7 +11027,7 @@ gtk_window_update_debugging (void)
   if (inspector_window &&
       gtk_window_update_debugging_id == 0)
     {
-      gtk_window_update_debugging_id = gdk_threads_add_idle (update_debugging, NULL);
+      gtk_window_update_debugging_id = g_idle_add (update_debugging, NULL);
       g_source_set_name_by_id (gtk_window_update_debugging_id, "[gtk+] gtk_window_update_debugging");
     }
 }
index 8bce079719f3c83cf34ba1f934825768876b1be5..bbf745e60f55fd781963591a1b8c9c2c2ffc5302 100644 (file)
@@ -142,7 +142,7 @@ main (gint argc, gchar **argv)
 
   gtk_widget_show (GTK_WIDGET (info.window));
   
-  gdk_threads_add_idle (stress_test_old_api, &info);
+  g_idle_add (stress_test_old_api, &info);
 
   gtk_widget_show (GTK_WIDGET (info.window));
   
index 34f45b690a510060927698b6dd78b658f1df7be9..e23f7b5bd91fc7deb8cf06c6df1fa38f93a94ebb 100644 (file)
@@ -219,7 +219,7 @@ static void
 process_pending_idles ()
 {
   GMainLoop *loop = g_main_loop_new (NULL, FALSE);
-  gdk_threads_add_idle (quit_loop, loop);
+  g_idle_add (quit_loop, loop);
   g_main_loop_run (loop);
 }